package ro.upt.dcda.pricezone.s1.requests.admin;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import ro.upt.dcda.pricezone.common.ConnectionFactory;
import ro.upt.dcda.pricezone.s1.pojo.Product;

public class AdminNewProductRequest {


	public boolean work(String name, String description) {
		Session session = ConnectionFactory.getFactory().openSession();
		Transaction tx = null;
		try {
			tx = session.beginTransaction();
			Product prod=new Product();
			prod.setName(name);
			prod.setDescription(description);
			session.saveOrUpdate(prod);
			tx.commit();
			return true;
		} catch (HibernateException e) {
			if (tx != null)
				tx.rollback();
			e.printStackTrace();
			return false;
		} finally {
			session.close();
		}
	}

}
